package com.finance.cooperate.data.service.impl;

import com.finance.cooperate.dao.repository.secondary.ScrapyAppRepository;
import com.finance.cooperate.dao.support.dto.ScrapyAppCategoriesDTO;
import com.finance.cooperate.data.service.ScrapyAppsCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName ScrapyAppsCacheServiceImpl
 * @Description TODO
 * @Author shenanxin
 * @Date 2023/10/18 09:40
 * @Modify ...
 */
@Service
@Slf4j
public class ScrapyAppsCacheServiceImpl implements ScrapyAppsCacheService {

    public static final String CACHE_NAME = "scrapy";

    @Autowired
    private ScrapyAppRepository scrapyAppRepository;

    @Cacheable(value = CACHE_NAME, key = "'key_'+#categoriesId", unless = "#result==null")
    @Override
    public List<ScrapyAppCategoriesDTO> getByCategories(String categoriesId) {

        List<ScrapyAppCategoriesDTO> result = scrapyAppRepository.findByCategories(categoriesId);

        return result;
    }
}
